from datetime import datetime

from sqlalchemy import Column, Integer, String, CHAR, DECIMAL, DATETIME

from app.models.base import Base, db


class wxpay_order(Base):
    __tablename__ = 'wxpay_order'
    id = Column(Integer, primary_key=True, autoincrement=True)
    out_trade_no = Column(String(40), default='')
    prepay_id = Column(String(70), default='')
    payer = Column(Integer, default=0)
    place_time = Column(DATETIME)
    pay_time = Column(DATETIME)
    pay_amount = Column(DECIMAL(10, 2), default=0)
    total_amount = Column(DECIMAL(10, 2), default=0)
    transaction_id = Column(String(40), default='')
    trade_type = Column(String(20), default='JSAPI')
    trade_state = Column(String(32), default='')
    appid = Column(String(40), default='')
    mchid = Column(String(40), default='')
    trade_state_desc = Column(String(500), default='')
    bank_type = Column(String(40), default='')
    attach = Column(String(150), default='')

    def keys(self):
        return ['id', 'out_trade_no', 'prepay_id', 'place_datetime', 'pay_time', 'pay_amount', 'total_amount',
                'transaction_id', 'trade_type', 'trade_state']

    @property
    def place_datetime(self):
        return str(self.place_time)
